package com.app.utils;


import com.app.basic.dao.service.SysUserService;
import com.app.basic.dao.entity.SysUser;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;


@Component
public class UserContext implements ApplicationContextAware {

    private static SysUserService sysUserService;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        UserContext.sysUserService = applicationContext.getBean(SysUserService.class);
    }


    public static SysUser getUser() {
        return sysUserService.lambdaQuery().eq(SysUser::getUsername, SecurityUtils.getSubject().getPrincipal()).one();
    }

    public static String getUsername(){
        return getUser().getUsername();
    }


}
